package com.dg.aichebao.pickphoto;

import android.app.Activity;
import android.content.Intent;
import android.provider.MediaStore;
import android.util.Log;

import com.dg.aichebao.pickphoto.util.PickConfig;
import com.dg.aichebao.pickphoto.util.PickUtils;
import com.donggua.aichebao.photo.DGPhotoBase;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by fzh on 2017/8/17.
 */

public class DGPhotoPick extends DGPhotoBase {

    public DGPhotoPick(Activity act) {
        super(act);
    }

    @Override
    public void startCamera() {
        Log.e("cam"," startCamera");
        try {
            File photoFile = PickUtils.getInstance(activity).getPhotoFile(activity);
            photoFile.delete();
            if (photoFile.createNewFile()) {
                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, PickUtils.getInstance(activity).getUri(photoFile));
                activity.startActivityForResult(intent, PickConfig.CAMERA_PHOTO_DATA);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void showPhotoPic() {
        Log.e("cam"," showPhotoPic");
        new PickPhotoView.Builder(activity)
                .setPickPhotoSize(mPicNumber)
                .setShowCamera(true)
                .setSpanCount(3)
                .setLightStatusBar(true)
                .setStatusBarColor("#ffffff")
                .setToolbarColor("#ffffff")
                .setToolbarIconColor("#000000")
                .setSelectIconColor("#00C07F")
                .setClickSelectable(true)
                .start();
    }

    @Override
    public void stopCamera() {

    }

    @Override
    public List<String> onActivityResult(int requestCode, int resultCode, Intent data) {
        Log.e("size"," requestCode is "+requestCode+" resultCode is "+resultCode);
        if(resultCode == 0){
            return null;
        }
        if(data == null){
            return null;
        }
        if (requestCode == PickConfig.PICK_PHOTO_DATA) {
            ArrayList<String> selectPaths = (ArrayList<String>) data.getSerializableExtra(PickConfig.INTENT_IMG_LIST_SELECT);
            Log.e("size"," selectPath si "+selectPaths);
            return selectPaths;
        }
        return null;
    }
}
